import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sf.json.JSONObject;

public class test {
   //测试
	/*private static String jsonStrBody ="{\"error\":0,\"status\":\"success\",\"date\":\"2015-01-15\",\"results\":[{\"currentCity\":\"南京\",\"pm25\":\"83\",\"index\":[{\"title\":\"穿衣\",\"zs\":\"较冷\",\"tipt\":\"穿衣指数\",\"des\":\"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。\"},{\"title\":\"洗车\",\"zs\":\"较适宜\",\"tipt\":\"洗车指数\",\"des\":\"较适宜洗车，未来一天无雨，风力较小，擦洗一新的汽车至少能保持一天。\"},{\"title\":\"旅游\",\"zs\":\"适宜\",\"tipt\":\"旅游指数\",\"des\":\"天气较好，气温稍低，会感觉稍微有点凉，不过也是个好天气哦。适宜旅游，可不要错过机会呦！\"},{\"title\":\"感冒\",\"zs\":\"少发\",\"tipt\":\"感冒指数\",\"des\":\"各项气象条件适宜，无明显降温过程，发生感冒机率较低。\"},{\"title\":\"运动\",\"zs\":\"较不宜\",\"tipt\":\"运动指数\",\"des\":\"阴天，且天气寒冷，推荐您在室内进行低强度运动；若坚持户外运动，请选择合适的运动并注意保暖。\"},{\"title\":\"紫外线强度\",\"zs\":\"最弱\",\"tipt\":\"紫外线强度指数\",\"des\":\"属弱紫外线辐射天气，无需特别防护。若长期在户外，建议涂擦SPF在8-12之间的防晒护肤品。\"}],\"weather_data\":[{\"date\":\"周四 01月15日 (实时：6℃)\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/yin.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"阴转多云\",\"wind\":\"北风微风\",\"temperature\":\"8 ~ 4℃\"},{\"date\":\"周五\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/duoyun.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/qing.png\",\"weather\":\"多云转晴\",\"wind\":\"西北风3-4级\",\"temperature\":\"12 ~ 0℃\"},{\"date\":\"周六\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/qing.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"晴转多云\",\"wind\":\"东北风3-4级\",\"temperature\":\"8 ~ 0℃\"},{\"date\":\"周日\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/qing.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/qing.png\",\"weather\":\"晴\",\"wind\":\"西风微风\",\"temperature\":\"10 ~ -1℃\"}]},{\"currentCity\":\"徐州\",\"pm25\":\"154\",\"index\":[{\"title\":\"穿衣\",\"zs\":\"较冷\",\"tipt\":\"穿衣指数\",\"des\":\"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。\"},{\"title\":\"洗车\",\"zs\":\"较适宜\",\"tipt\":\"洗车指数\",\"des\":\"较适宜洗车，未来一天无雨，风力较小，擦洗一新的汽车至少能保持一天。\"},{\"title\":\"旅游\",\"zs\":\"适宜\",\"tipt\":\"旅游指数\",\"des\":\"天气较好，但丝毫不会影响您出行的心情。温度适宜又有微风相伴，适宜旅游。\"},{\"title\":\"感冒\",\"zs\":\"较易发\",\"tipt\":\"感冒指数\",\"des\":\"天气较凉，较易发生感冒，请适当增加衣服。体质较弱的朋友尤其应该注意防护。\"},{\"title\":\"运动\",\"zs\":\"较不宜\",\"tipt\":\"运动指数\",\"des\":\"天气较好，但考虑天气寒冷，推荐您进行各种室内运动，若在户外运动请注意保暖并做好准备活动。\"},{\"title\":\"紫外线强度\",\"zs\":\"最弱\",\"tipt\":\"紫外线强度指数\",\"des\":\"属弱紫外线辐射天气，无需特别防护。若长期在户外，建议涂擦SPF在8-12之间的防晒护肤品。\"}],\"weather_data\":[{\"date\":\"周四 01月15日 (实时：6℃)\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/duoyun.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"多云\",\"wind\":\"南风微风\",\"temperature\":\"10 ~ 3℃\"},{\"date\":\"周五\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/duoyun.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"多云\",\"wind\":\"北风3-4级\",\"temperature\":\"11 ~ -4℃\"},{\"date\":\"周六\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/duoyun.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"多云\",\"wind\":\"东风微风\",\"temperature\":\"6 ~ -4℃\"},{\"date\":\"周日\",\"dayPictureUrl\":\"http://api.map.baidu.com/images/weather/day/duoyun.png\",\"nightPictureUrl\":\"http://api.map.baidu.com/images/weather/night/duoyun.png\",\"weather\":\"多云\",\"wind\":\"西风3-4级\",\"temperature\":\"11 ~ -1℃\"}]}]}";
	public static void main(String args[]) {
		// JSON转换
		JSONObject jsonObj = JSONObject.fromObject(jsonStrBody);
		
		Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
        classMap.put("results", WeatherBean_Baidu_City.class);
        classMap.put("index", WeatherBean_Baidu_City_Index.class);  
        classMap.put("weather_data", WeatherBean_Baidu_City_Weatherdata.class);  
        // 将JSON转换成WeatherBean_Baidu  
        WeatherBean_Baidu weather = (WeatherBean_Baidu) JSONObject.toBean(jsonObj,  
        		WeatherBean_Baidu.class, classMap); 
        
        for(WeatherBean_Baidu_City city: weather.getResults()) {
        	System.out.println(city.getIndex());
        	for(WeatherBean_Baidu_City_Index cityIndex : city.getIndex()) {
        		System.out.println(cityIndex.getTitle());
        	}
        	for(WeatherBean_Baidu_City_Weatherdata data : city.getWeather_data()) {
        		System.out.println(data.getDate());
        	}
        }
	}*/
	/**
	 * 匹配查询字符串中以某字符开始并且以某字符结束的中间内容
	 * 例如：{databaseIp}:{databasePort}{instanceName};database 查询出以{}包含的内容字符串并且返回list集合
	 * @param regText
	 * @param indexOfValue
	 * @param endOfValue
	 * @return
	 */
	public static List<String> parseMatcherList(String regText,String indexOfValue,String endOfValue){
		List<String> ls=new ArrayList<String>();
		//替换匹配正值表达式
		Pattern pattern = Pattern.compile("(?<=\\"+indexOfValue+")(.+?)(?=\\"+endOfValue+")");
		Matcher matcher = pattern.matcher(regText);
		while(matcher.find()){
			ls.add(matcher.group());
		}
		return ls;
	}
	public static void main(String args[]) {
		try {
			String test = "double zjd = double.Parse(｛中心距｝.ToString()) - Math.Round(double.Parse(ToNumber(【进口长度】).ToString()) * double.Parse(｛进口长度｝.ToString()) / (double)1000 / (double)2 ,3)  + a;";
			List<String> ls = parseMatcherList(test,"｛","｝");

			for (String string : ls) {

				System.out.println(string);

			}
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
